package com.example.wto.viewpagertest01;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by wto on 4/17/2017.
 */

public class CatalogAdapter extends ArrayAdapter<CatalogBean>
{
    private Context context;
    private int resource;
    private List<CatalogBean> catalogBeanList;
    public CatalogAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull
            List<CatalogBean> objects)
    {
        super(context, resource, objects);
        this.context=context;
        this.resource=resource;
        this.catalogBeanList=objects;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
    {
        CatalogBean catalogBean=catalogBeanList.get(position);
        if(convertView==null)
        {
            convertView= LayoutInflater.from(context).inflate(resource,parent,false);
        }
        TextView catalog=(TextView)convertView.findViewById(R.id.catalog_textview);
        catalog.setText(catalogBean.getName());
        return convertView;
    }
}
